﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Golos.BackEnd.Client;
using Golos.Users.UserCache;

namespace Golos.Polls.PollCache
{
    public partial class Cache
    {
        public Dictionary<UserIdType, int> GetDistributionBySocialweb(Guid questionId)
        {
            Dictionary<UserIdType, int> result = new Dictionary<UserIdType, int>();
            List<Guid> userIds = new List<Guid>();
            lock (lockcache)
            {
                
                if (!questionUserAnswers.ContainsKey(questionId))
                    throw new Exception(string.Format("Can't find QuestionId = {0}", questionId));
                userIds = questionUserAnswers[questionId].Keys.ToList();
            }
            foreach (var userId in userIds)
            {
                UsersClient usersClient = new UsersClient();
                UserInfo userInfo = usersClient.GetUserInfoByUserId(userId);
                foreach (UserIdType userIdType in userInfo.UserIdentification.Keys)
                {
                    if(!result.ContainsKey(userIdType))
                        result.Add(userIdType, 0);
                    result[userIdType]++;
                }
            }
            return result;
        }
    }
}
